<template>
  <div class="myindex1"> 
      <div class="myindex1header">
          <span> ＜ </span>
          <span>登录</span>
      </div>
      <button @click="getUserProfile"> 点击登录 </button>
      <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权手机号</button>
  </div>  
</template>

<script>
export default {
  data() {
    return {
      username:""
    }
  },
  onLoad(){
    let name= wx.getStorageSync('username')
    if (name) {
        wx.navigateTo({
          url:'/pages/my/index2'
        })
    }
  },
  methods: {
      getUserProfile(){
        wx.getUserProfile({
          desc:"获取您的用户信息",
          success(e){
            console.log(e,'eeeee');
              wx.setStorageSync('username',e.userInfo.nickName)
              wx.setStorageSync('avatarUrl',e.userInfo.avatarUrl)
              wx.navigateTo({
                url:"/pages/my/index2"
              })
          }
        })
      },
      getPhoneNumber(e){
            console.log(e.detail);
            wx.showRedPackage({
                success(e){
                  console.log(e);
                }
            })
      }
  },
}
</script>

<style scoped lang="scss">
  .myindex1header{
    width: 100%;
    height: 150rpx;
    display: flex;
    padding-top: 70rpx;	
    color: white;
		background-image: linear-gradient(#0272f0, #329efd);
    span:nth-child(1){
      padding-left: 20rpx;
    }
    span:nth-child(2){
      margin-left: 280rpx;
    }
  }
  button{
    width: 40%;
  }
</style>